package com.swgk.core.customview;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.swgk.core.R;


public class SquareTextView extends RelativeLayout {

    private Context context;
    private View squre_view;
    private TextView name_tv;

    private boolean canInput;

    private int infilterType;

    public SquareTextView(Context context) {
        this(context, null);
    }

    public SquareTextView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SquareTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        init();
        perseAttrs(attrs);
    }

    private void init() {
        View view = LayoutInflater.from(context).inflate(R.layout.view_item_squre_text, this);
        squre_view = view.findViewById(R.id.squre_view);
        name_tv = view.findViewById(R.id.name_tv);
    }

    public void setLabelName(int nameId) {
        name_tv.setText(nameId);
    }

    public void setLabelName(String name) {
        name_tv.setText(name);
    }


    public void setLableColor(int color) {
        name_tv.setTextColor(getResources().getColor(color));
    }

    public void setSqureViewBg(int drw) {
        squre_view.setBackgroundResource(drw);
    }

    private void perseAttrs(AttributeSet attrs) {
        if (attrs != null) {
            TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SquareTextView);
            //遍历AttributeSet中的XML属性
            //设置label名字
            name_tv.setText(typedArray.getString(R.styleable.SquareTextView_itv_name_text));
            //设置颜色
            name_tv.setTextColor(typedArray.getColor(R.styleable.SquareTextView_itv_name_color, getResources().getColor(R.color.color_main_bg)));
            typedArray.recycle();
        }
    }
}